package WaitNotify.demo3;

import java.util.Hashtable;
import java.util.Map;
import java.util.Set;


public class MailBox {
    //           id 与  GuardedObject 一一对应
    private static Map<Integer,GuardedObject> box = new Hashtable<>();

    //唯一id
    private static int id;

    public static synchronized int getUniqueID() {
        return id++;
    }

    public static GuardedObject CreateGuardedObject() {
        GuardedObject guardedObject = new GuardedObject(getUniqueID());
        box.put(guardedObject.getId(),guardedObject);
        return guardedObject;
    }

    public static GuardedObject getGuardedObject(int id) {
        return box.remove(id);
    }

    //获取到所有的id
    public static Set<Integer> getAllId() {
        return box.keySet();
    }
}
